﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace NumericalMethod
{
    public partial class StatusForm : UserControl
    {
       const int maxScroll = 100000;
        private const string css = "<html><head><style> p, td {" +
            "font-family:\"Lucida Sans Unicode\", \"Lucida Grande\", sans-serif;" +
            "font-size:12px;" +
            "margin: 0px;" +
            "} </style></head><body></body></html>";
        
        public StatusForm()
        {
            InitializeComponent();
        }
        public void AppendOutput(string output)
        {
           HtmlElement p = webBrowser.Document.CreateElement("P");
           p.InnerHtml=output;
               
           webBrowser.Document.Body.AppendChild(p);
           webBrowser.Document.Body.ScrollTop = maxScroll;
        }
        public void AppendHTML(string output)
        {
           webBrowser.Document.Body.InnerHtml += output;
           webBrowser.Document.Body.ScrollTop = maxScroll;
        }
        public void SetColumn(string[] colums)
        {
            viewWhat.Clear();
            foreach (string txt in colums)
            {
                viewWhat.Columns.Add(txt);
            }
            //usually 1st column is more smaller
            viewWhat.Columns[0].Width = 20;
        }
        public void ClearRow()
        {
            viewWhat.Items.Clear();
        }
        public void InsertRow(string[] text)
        {
            viewWhat.Items.Add(new ListViewItem(text));
        }
        private void clearList_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            webBrowser.Document.Body.InnerHtml = "";
        }

        private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
        {
           resize();
        }
       /// <summary>
       /// Hide which panel?
       /// </summary>
       /// <param name="pane">0 is none, 1 is up, 2 is down</param>
        public void HidePanel( int pane )
        {
           if ( pane == 1 )
           {
              splitContainer1.Panel1Collapsed = true;
              splitContainer1.Panel2Collapsed = false;
           }
           else if (pane == 0)
           {
              splitContainer1.Panel1Collapsed = false;
              splitContainer1.Panel2Collapsed = false;
           }
           else
           {
              splitContainer1.Panel1Collapsed = false;
              splitContainer1.Panel2Collapsed = true;
           }
           resize();
        }

        private void StatusForm_Load(object sender, EventArgs e)
        {
           webBrowser.DocumentText = css;
           webBrowser.IsWebBrowserContextMenuEnabled = false;
        }

        private void resize()
        {
           //viewWhat.Size = new Size(viewWhat.Size.Width, splitContainer1.Panel2.Height);
           webBrowser.Size = new Size(webBrowser.Size.Width, splitContainer1.Panel1.Height - 15);
           clearList.Location = new Point(clearList.Location.X, splitContainer1.Panel1.Height - 13);
        }
    }
}
